<%@ include file="/common/taglibs.jsp" %>

<link href="<c:url value='/css/tablesorter.css' />" rel="stylesheet" type="text/css"/>
<link href="<c:url value='/css/dhtmlxcombo.css' />" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
	$(document).ready(function() {
		$('#editPaymentrequestForm input, #editPaymentrequestForm select').keypress(function(e) {
      		if(e.which == 13) {      
            	jQuery('#loginFormSubmit').click();
            	return false;
       		}
   		});
		
		$('#pageTitle').text('<spring:message code="findPaymentrequest.heading" />');
		
// 		$("#editPaymentrequestForm").validate({
// 			rules : {
// 				paymentIdentifiedInformation : {
// 					number: true
// 				}
// 			}
// 		});
		$("#resetForm").click(function(){	
			$(this).bind("ajaxSend", function(){

				$(this).after("<img  id='loading' src='<c:url value='/images/ajax-loader.gif'/>' alt='loading' />");

				 }).bind("ajaxComplete", function(){
					$('#loading').remove();
				 })
			$("#content").load("../secure/findPaymentrequest.do");
		});
		

	});
	$(document).ready(sortDropDownListByText);
	$(function() {
		$("#startDate").datepicker();
	});

	$(function() {
		$("#endDate").datepicker();
	});
	
		
	
	function sortDropDownListByText() {
	    // Loop for each select element on the page.
	  
	    $("select").each(function() {
	         
	        // Keep track of the selected option.
	        var selectedValue = $(this).val();
	 
	        // Sort all the options by text.
	        $(this).html($("option", $(this)).sort(function(a, b) {
	        	//return a.text == $(selectId + 'option:first').text ? -1 : a.text < b.text ? -1 : 1;
	        	
	           return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
	        }));
	 
	        // Select one option.
	        $(this).val(selectedValue);
	    });
	}
	$('.close-button').click(function() {
		loadDiv('content', 'refreshDashboard.do');
     });
	

		
	


		$('#loginFormSubmit').click(function() {	
			$(this).bind("ajaxSend", function(){
				
				$('#loading').remove();
				$(this).after("<img  id='loading' src='<c:url value='/images/ajax-loader.gif'/>' alt='loading' />");

				 }).bind("ajaxComplete", function(){

					$('#loading').remove();

				 });
		
		
		  var v1= $('#id').val();
		  //var v2= $('#createdBy\\.id').val();
		   var v2= $('.dhx_combo_input').eq(0).val();
		 // var v3= $('#payee\\.id').val();
		  var v3= $('.dhx_combo_input').eq(1).val();
		 
		  //var v4= $('#statusCode').val();
		   var v4= $('.dhx_combo_input').eq(2).val();
		 
		  var v5= $('#startAmount').val();
		  var v6= $('#endAmount').val();
		  var v7= $('#startDate').val();
		  var v8= $('#endDate').val();
		  var v9= $('#costcenternumber').val();
		//   var v9= $('.dhx_combo_input').eq(3).val();
		   
		 // var v10= $('#accountcode\\.id').val();
		  var v10= $('.dhx_combo_input').eq(3).val();
		 
		  //var v11=$('#paymenttype\\.id').val();
		  var v11= $('.dhx_combo_input').eq(4).val();
		  var v12= $('.dhx_combo_input').eq(5).val();
		//  alert(v12);
		  if(v7!=''|| v8!=''){
		     if(v7==''){
			    alert("Please select valid start date query criteria. Start date can not be null. Leave blank both field  or enter valid range");
			     return false;
			   } else if(v8==''){
			    alert("Please enter valid start date query criteria. End date can not be null. Leave blank both field  or enter valid range");
			    return false;
			   } else if((new Date(v7)).getTime()> (new Date(v8)).getTime() ){
			     alert('Start date should be before end date');
			      return false;
			   }
			   
		  }
		  if(v5!=''|| v6!=''){
			   if(v5==''){
			    alert("Please enter valid amount query criteria. Start amount can not be null. Leave blank both field  or enter valid range");
			     return false;
			   } else if(v6==''){
			    alert("Please enter valid amount query criteria. End amount can not be null. Leave blank both field  or enter valid range");
			    return false;
			   }
		  
		  }
		  
		 if( v1!='' || v2!='' || v3!=''|| v4!='' || v5!='' || v6!='' || v7!='' || v8!='' || v9!='' || v10!='' || v11!='' || v12!=''){		    
		   return true;
		 }
		 alert("Please enter at least one filter criteria");
		 return false;
			
				
		
		});
		
		var z = dhtmlXComboFromSelect("createdBy_id",274);
		z.enableFilteringMode(true);
		
		var z1 = dhtmlXComboFromSelect("payee_id",274);
		z1.enableFilteringMode(true);
		
		var z2 = dhtmlXComboFromSelect("statusCode",274);
		z2.enableFilteringMode(true);
		
		var z4 = dhtmlXComboFromSelect("accountcode_id",274);
		z4.enableFilteringMode(true);
		
		var z5 = dhtmlXComboFromSelect("paymenttype_id",274);
		z5.enableFilteringMode(true);
	    
	    var z6 = dhtmlXComboFromSelect("paymentMethod",274);
		z6.enableFilteringMode(true);						
		
			
   /*
    $('#check-all').click(function() {    
        var checkBox = $('#paymentRqst input:checkbox');
        for(var i = 0; i < checkBox.length; i++) {
     	   checkBox[i].checked = this.checked;
        }
 	});*/
    
</script>
<div id="findPaymentReqDonorDiv" >
	<form:form name="editPaymentrequestForm" id="editPaymentrequestForm" action="findPaymentrequest.do" method="GET" modelAttribute="paymentrequest">
<%-- 		<form:hidden path="id" /> --%>
	    <div class="main_form">
	    	<div class="form_head">
	    		<a href="#" class="close-button gray_btn floatR" tabindex="-1">Close Form</a><br class="clear" />
	    	</div>
	        <div class="form_cont">
				<table cellspacing="5" width="100%">
					<tr class="row">
						<td class="input-field" colspan="5">
							<%@ include file="/common/messages.jsp" %>
						</td>
					</tr>		  
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.paymentIdentifiedInformation" /></td>
						<td class="input-field">
							<form:input path="id" cssClass="input-full-width text_white" tabindex="1" id="id"/>
							<form:errors path="id" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="findPaymentrequest.label.createdBy" /></td>
						<td class="input-field">
							<form:select path="createdBy.id" cssClass="text_white" tabindex="6" id="createdBy_id">
								<form:option value="" label="" />
								<form:options items="${userList}" itemValue="id" itemLabel="fullName" />
							</form:select>
							<form:errors path="createdBy.id" cssClass="error" />
						</td>
					</tr>
				
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.payee" /></td>
						<td class="input-field">
							<form:select path="payee.payeeName" cssClass="text_white" tabindex="2" id="payee_id">
								<form:option value="" label="" />
								<form:options items="${payeeList}" itemValue="payeeName" itemLabel="payeeName" />
							</form:select>
							<form:errors path="payee.payeeName" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editPaymentrequest.label.statusCode" /></td>
						<td class="input-field">
							<form:select path="statusCode" cssClass="text_white" tabindex="7" id="statusCode">
						        <form:option value="" label="" />
								<form:option value="New" label="New" />
								<form:option value="In Finance" label="In Finance" />
								<form:option value="Awaiting Signature" label="Awaiting Signature" />
								<form:option value="Pending Payment" label="Pending Payment" />
								<form:option value="Paid" label="Paid" />
								<form:option value="Rejected" label="Rejected" />
								<form:option value="Cancel Requested" label="Cancel Requested" />
								<form:option value="Resubmitted" label="Resubmitted"/>
								<!--form:option value="Inactive" label="9) Inactive" /-->																
								<form:option value=" Cancelled" label="  Cancelled" />
							</form:select></td>
							<form:errors path="statusCode" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.AmountBetween" /></td>
						<td class="input-field">
							<form:input path="startAmount" cssClass="input-full-width text_white" tabindex="3"/>
							<form:errors path="startAmount" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label">And</td>
						<td class="input-field">
							<form:input path="endAmount" cssClass="input-full-width text_white" tabindex="8"/>
							<form:errors path="endAmount" cssClass="error" />
						</td>
					</tr>
					<tr class="row">
						<td class="label"><spring:message code="editPaymentrequest.label.dateBetween" /></td>
						<td class="input-field">
							<form:input path="startDate" cssClass="input-full-width text_white" tabindex="9"/></td>
							<form:errors path="startDate" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label">And</td>
						<td class="input-field">
							<form:input path="endDate" cssClass="input-full-width text_white" />
							<form:errors path="endDate" cssClass="error" />
						</td>
					</tr>
					 <tr class="row">
						<td class="label"><spring:message code="editCipeproject.label.costCenter" /></td>
						<td class="input-field">
						<form:input path="costcenternumber" cssClass="input-full-width text_white" id="costcenternumber"/>
						 <!--
							<form:select path="costcenternumber" cssClass="text_white" tabindex="4" id="costcenternumber">
								<form:option value="" label="" />
								<form:options items="${projectList}" itemValue="costCenterNumber" itemLabel="costCenterNumber" />
							</form:select>
						 -->	
							<form:errors path="costcenternumber" cssClass="error" />
						</td>
						<td width="50">&nbsp;</td>
						<td class="label"><spring:message code="editAccountCode.label.displayName" /></td>
						<td class="input-field">
							<form:select path="accountcode.id" cssClass="text_white" tabindex="10" id="accountcode_id">
								<form:option value="" label="" />
								<form:options items="${accountCodeList}" itemValue="id" itemLabel="displayName" />
							</form:select>
							<form:errors path="accountcode" cssClass="error" />
						</td>
					</tr>
					
					<tr>
	                	<td class="label"><spring:message code="editPaymentrequest.label.paymentrequesttype" /></td>
	                	<td>	<form:select path="paymenttype.id" cssClass="input-full-width-req text_white" tabindex="5" id="paymenttype_id">
						       	<form:option value="" label="" tabindex="11"/>
								<form:options items="${paymenttypeList}" itemValue="id" itemLabel="paymenttypename" />
							</form:select></td>
	                	<td width="50"></td>
	                	<td class="label"><spring:message code="editPaymentrequest.label.paymentmethod" /></td>
	                	<td class="input-field" nowrap="nowrap">
	                	<form:select path="paymentmethod"  id ="paymentMethod" cssClass="input-full-width-req text_blue" tabindex="2">
                              <form:option value="" label="" />
                              <form:option value="Wire" label="Wire" />
                            <form:option value="Check" label="Check" />
	                	</form:select>
													
						</td>
	              	</tr>
					<tr class="row">
						<td class="input-field" align="center" colspan="5">
							<sj:submit id="loginFormSubmit" name="initiateSearch" cssClass="blue_btn" target="content" key="findDonoraward.button.search" validate="true" tabindex="-1"/>
							
							<input id="resetForm" type="button"  class="blue_btn" value="<spring:message code='button.resetSearch' />" tabindex="-1" />
						</td>
					</tr>
				</table>
				  		
				<div id="paymentReqListDiv" class="hastable" style="overflow: auto">
				<c:if test="${!empty initiateSearch }">	              		
	                  <jsp:include page="/WEB-INF/jsps/searchFindPaymentRequest.jsp" />
	            </c:if>
	            </div>      				
	                
                
			</div>
		</div>
	</form:form>
</div>
